package nrrg.zhujuxing.application.learnscala

object commonWordCount {
  def main(args: Array[String]): Unit = {
    val stringList = List(
      "hello",
      "hello world",
      "hello scala",
      "fuck you"
    )

    val wordList1: List[String] = stringList.flatMap((_: String).split(" "))
    println(wordList1)

    val wordListGroup: Map[String, List[String]] = wordList1.groupBy((w: String) => w)
    println(wordListGroup)

    val wordCount: Map[String, Int] = wordListGroup.map((kv: (String, List[String])) => (kv._1, kv._2.length))
    println(wordCount)

    val sortedList: List[(String, Int)] = wordCount
      .toList
      .sortWith((_: (String, Int))._2 > (_: (String, Int))._2)
      .take(3)
    println(sortedList)

  }

}
